package com.soso.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.soso.dao.RolesDao;
import com.soso.entity.Roles;
import com.soso.entity.RolesSercher;
import com.soso.service.RolesService;
import com.soso.util.UUIDutils;

@Controller
public class RolesController {
@Autowired
	private RolesDao rolesdaos;
@Autowired
private RolesService rse;

	@RequestMapping("/getrolesalls")
	@ResponseBody
	@CrossOrigin(origins = "*")
	public Map<String, Object> getrolesalls(){
		List<Roles> l=rolesdaos.getroles();
		Map<String, Object> maps=new HashMap<String, Object>();
		if(l!=null) {
			maps.put("code", "0");
			maps.put("msg", "true");
			maps.put("count", 10);
			maps.put("data", l);
		}else {
			maps.put("code", "1");
			maps.put("msg", "false");
		
		}
		return maps;
	
	}
	
    @RequestMapping("/findPage")
    @ResponseBody
	@CrossOrigin(origins = "*")
    public Object findAll(RolesSercher rs,Integer page,Integer limit) {
		return rse.findpage(rs, page, limit);
    }
    @RequestMapping("/saveRoles")
    @ResponseBody
    @CrossOrigin(origins = "*")
    public Integer saveroles(String Name,String Id,Roles r){
    	

    	System.out.println(Name);
    	System.out.println(Id);
    	r.setId(Id);
    	r.setName(Name);
    
		 return rse.saveRoles(r); 
    
    }
    
    @RequestMapping("/addRoles")
    @ResponseBody
	@CrossOrigin(origins = "*")
    public Integer add(String Id, String Name) {
    	String uuid=UUIDutils.getUUID();
		return rse.adda(uuid, Name);
    	
    }
    
    @RequestMapping("/deleRoleas")
    @ResponseBody
	@CrossOrigin(origins = "*")
    public Integer deleRoleas(String id) {
    	try {
    		rse.deleteromoid(id);
        	rse.deletero(id);
        	return 1;
		} catch (Exception e) {
			return 0;
		}
    }
	
	
	
}
